package com.xindaoapp.henghua.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xindaoapp.henghua.R;
import com.xindaoapp.henghua.entry.PropertyGatherInfo;
import com.xindaoapp.henghua.entry.TransportDataInfo;

@SuppressLint("NewApi")
public class DetailFragment extends XDBaseFragment {

	private final String TAG = "DetailFragment";

	private TextView tv_1, tv_1_2;
	private TextView tv_2, tv_2_2;
	private TextView tv_3, tv_3_2;
	private TextView tv_4, tv_4_2;
	private TextView tv_5;
	private TextView tv_6, tv_6_2;
	private TextView tv_7, tv_7_2;
	private TextView tv_8;
	private TextView et_label;

	/** 获取设备相关所有信息*/
	private PropertyGatherInfo info = null;

	public static DetailFragment newInstance(Bundle args) {
		final DetailFragment f = new DetailFragment();

		f.setArguments(args);

		return f;
	}

	@Override
	protected void initUi() {
		tv_1 = (TextView) findViewById(R.id.tv_label_1);
		tv_1_2 = (TextView) findViewById(R.id.tv_label_1_2);
		tv_2 = (TextView) findViewById(R.id.tv_label_2);
		tv_2_2 = (TextView) findViewById(R.id.tv_label_2_2);
		tv_3 = (TextView) findViewById(R.id.tv_label_3);
		tv_3_2 = (TextView) findViewById(R.id.tv_label_3_2);
		tv_4 = (TextView) findViewById(R.id.tv_label_4);
		tv_4_2 = (TextView) findViewById(R.id.tv_label_4_2);
		tv_5 = (TextView) findViewById(R.id.tv_label_5);
		tv_6 = (TextView) findViewById(R.id.tv_label_6);
		tv_6_2 = (TextView) findViewById(R.id.tv_label_6_2);
		tv_7 = (TextView) findViewById(R.id.tv_label_7);
		tv_7_2 = (TextView) findViewById(R.id.tv_label_7_2);
		tv_8 = (TextView) findViewById(R.id.tv_label_8);
		et_label = (TextView) findViewById(R.id.et_label);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Log.d(TAG, "onCreate");

		info = (PropertyGatherInfo) getArguments().getSerializable("info");

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		Log.d(TAG, "onCreateView");

		mView = inflater.inflate(R.layout.fragment_detail, container, false);

		return mView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		Log.d(TAG, "onActivityCreated");

		String str = "";
		if (info != null) {

			str = info.id;
			if (!TextUtils.isEmpty(str)) {
				tv_1.setText(str);
			}
			str = info.name;
			if (!TextUtils.isEmpty(str)) {
				tv_1_2.setText(str);
			}
			str = info.model;
			if (!TextUtils.isEmpty(str)) {
				tv_2.setText(str);
			}
			str = info.type;
			if (!TextUtils.isEmpty(str)) {
				tv_2_2.setText(str);
			}
			str = info.factory_name;
			if (!TextUtils.isEmpty(str)) {
				tv_3.setText(str);
			}
			str = info.factory_code;
			if (!TextUtils.isEmpty(str)) {
				tv_3_2.setText(str);
			}
			str = info.factory_phone;
			if (!TextUtils.isEmpty(str)) {
				tv_4.setText(str);
			}
			str = info.factory_linkman;
			if (!TextUtils.isEmpty(str)) {
				tv_4_2.setText(str);
			}
			str = info.factory_addr;
			if (!TextUtils.isEmpty(str)) {
				tv_5.setText(str);
			}
			str = info.supervision_unitname;
			if (!TextUtils.isEmpty(str)) {
				tv_6.setText(str);
			}
			str = info.supervision_unitcode;
			if (!TextUtils.isEmpty(str)) {
				tv_6_2.setText(str);
			}
			str = info.supervision_mode;
			if (!TextUtils.isEmpty(str)) {
				tv_7.setText(str);
			}
			str = info.supervision_linkman;
			if (!TextUtils.isEmpty(str)) {
				tv_7_2.setText(str);
			}

			if (info.scanDatas == null) {
				tv_8.setText("未出厂");
			} else {
				tv_8.setText("已出厂");
			}

			TransportDataInfo transportDataInfo = info.transportDataInfo;
			if (transportDataInfo != null) {
				str = transportDataInfo.notes;
				if (!TextUtils.isEmpty(str)) {
					et_label.setText(str);
				}
			}

		}

	}

}
